package com.atguigu.gmall;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author: atguigu
 * @create: 2023-03-01 09:07
 */
public class CompletableFutureTest1 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //1.创建线程A异步操作对象-需求线程A有返回结果
        CompletableFuture<Void> futureA = CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName() + "\t线程A执行了");
        });



        CompletableFuture<Void> futureB = CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName() + "\t线程B执行了");
        });


        //allOf:所有异步任务执行完成后,代码继续执行后面代码
        //CompletableFuture.allOf(futureA, futureB).join();
        CompletableFuture.anyOf(futureA, futureB).join();
        System.out.println(Thread.currentThread().getName()+",继续执行..");
    }
}
